﻿//创建人：longb
//日期：2022-06-07
//描述：齐套统计分析
var page = {
    selectID: null,
    rowindex: 0,
    pagetotal: 0,
    pageSize: 20,
    pageNumber: 1,
    rootPath: getRootPath(), //网站根路径
    ajaxUrl: getRootPath() + "/Ashx/ZsHandler/ZSFullSetStatisticsAnalysisHandler.ashx",
    //初始化页面
    init: function () {
        page.bind();
        NewcustomizedEasyuiPagination('pp'); //定制化分页
        $('#pageSize').combobox({
                    editable:false,
                    prompt:'分页条数',
                    data:[{id:50,text:'50条/页'},{id:100,text:'100条/页'},{id:150,text:'150条/页'},{id:200,text:'200条/页'},{id:300,text:'300条/页'},{id:500,text:'500条/页'}],
                    valueField:'id',
                    textField:'text',
                    onSelect:function(record){
                        page.pageSize=record.id;
                    }
                });
    },
    //页面事件绑定
    bind: function () {
        $('#SetTime').datetimebox('setValue', new Date());
        $('#OrderTabel').datagrid({
            checkOnSelect: false,
            selectOnCheck: false,
            singleSelect: true,
            rownumbers: true,
            columns: [[
                 { field: 'ATTRIBUTEVALUE', title: '发动机号', width: 120 },
                 { field: 'MFGORDERNAME', title: '订单号', width: 150 },
		         { field: 'TOGETHERFLAG', title: '任务单号', width: 150 },
                 { field: 'DESCRIPTION', title: '件号名称', width: 110 },
                 { field: 'WORKFLOWSTEPNAME', title: '阶段', width: 100 },
                 { field: 'QTL', title: '齐套率', width: 70, align: 'center', formatter: function (value, row, index) { 
                    //if(row.STEPCOUNT==null){return "--";} else{ return parseInt(row.QT / row.STEPCOUNT*100) + '%';} } 
                    return parseInt(value*100) + '%';
                    } 
                 },
                 { field: 'FULLTIME', title: '预计齐套时间', width: 150 }
                ]],
            onSelect: function (index, row) {
                page.GetSpec();
                page.GetBigSmallData('');
                page.selectID = null;
            },
            onUnselect: function () {
                $('#BigTabel').datagrid('loadData', []);
                $('#SmallTabel').datagrid('loadData', []);
            },
            onLoadSuccess: function (data) {
                $('#pp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
                    total: page.pagetotal,
                    pageSize: page.pageSize,
                    pageNumber: page.pageNumber
                });
                NewcustomizedEasyuiPagination('pp'); //定制化分页
               
            },
        });
        //分页事件
        $('#pp').pagination({
            onSelectPage: function (pageNumber, pageSize) {
                NewcustomizedEasyuiPagination('pp'); //定制化分页
                page.pageSize = pageSize; page.pageNumber = pageNumber;
                page.GetTaskOrderData();
            }
        });
        //绑定分页go按钮
        $('#pageGo').on("click", function () {
            var pageNumber = Number((this).parents('tr').find('.pagination-num').val());
            page.pageSize=$('#pp').find('.pageSize').combobox('getValue')==''?20:Number($('#pp').find('.pageSize').combobox('getValue'));
            page.pageNumber = pageNumber;
            page.GetTaskOrderData();
        });
       

        $('#SpecTable').datagrid({
            checkOnSelect: false,
            selectOnCheck: false,
            singleSelect: true,
            columns: [[
		        { field: 'SPECNO', title: '工序号', width: 80 },
		        { field: 'OPDESC', title: '工序名称', width: 150 },
		        { field: 'QTL', title: '齐套率', width: 70, align: 'center', formatter: function (value, row, index) { if (row.PCOUNT == 0) { return "--"; } else { return parseInt(row.CCOUNT / row.PCOUNT * 100) + '%'; } } },
                { field: 'PLANNEDSTARTDATE', title: '计划开始时间', width: 100, align: 'center' },
                { field: 'FULLTIME', title: '预计齐套时间', width: 150, align: 'center' }
                ]],
            onSelect: function (index, row) {
                page.GetBigSmallData(row.SPECID);
            }
        });
        $('#BigTabel').datagrid({
            //checkOnSelect: false,
            //selectOnCheck: false,
            singleSelect: true,
            columns: [[
		        { field: 'PRODUCTNAME', title: '件号', width: 100 },
		        { field: 'DESCRIPTION', title: '件号名称', width: 100 },
		        { field: 'FIRSTASSEMBLEQTY', title: '单台数量', width: 100, align: 'center' },
                { field: 'CONFIRMQTY', title: '实际数量', width: 100, align: 'center' },
                { field: 'QTL', title: '齐套率', width: 100, align: 'center', formatter: function (value, row, index) { return parseInt(row.CONFIRMQTY / row.FIRSTASSEMBLEQTY * 100) + '%'; } },
                { field: 'FULLTIME', title: '预计齐套时间', width: 150, align: 'center' }
                ]],
            onSelect: function (index, row) {
                page.selectID = "BigTabel";
                page.rowindex = index;
            }
        });
        $('#SmallTabel').datagrid({
            //checkOnSelect: false,
            //selectOnCheck: false,
            singleSelect: true,
            columns: [[
                { field: 'PRODUCTNAME', title: '件号', width: 100 },
		        { field: 'DESCRIPTION', title: '件号名称', width: 100 },
		        { field: 'FIRSTASSEMBLEQTY', title: '单台数量', width: 100, align: 'center' },
                { field: 'CONFIRMQTY', title: '实际数量', width: 100, align: 'center' },
                { field: 'QTL', title: '齐套率', width: 100, align: 'center', formatter: function (value, row, index) { return parseInt(row.CONFIRMQTY / row.FIRSTASSEMBLEQTY * 100) + '%'; } },
                { field: 'FULLTIME', title: '预计齐套时间', width: 150, align: 'center' }
		        ]],
            onSelect: function (index, row) {
                page.selectID = "SmallTabel";
                page.rowindex = index;
            }
        });
    },
    //查询
    searchData: function () {
        clearMessage();
        $('#BigTable').datagrid('loadData', []);
         page.pageNumber = 1;
        page.GetTaskOrderData();
    },
    //查询重置
    searchReset: function () {
        $('#searchForm').form('clear');
        clearMessage();
    },
    //查询任务单信息
    GetTaskOrderData: function () {
        $('#SpecTable').datagrid('loadData', []);
        $('#BigTabel').datagrid('loadData', []);
        $('#SmallTabel').datagrid('loadData', []);
        var frdata = $('#searchForm').serializeArray();
        var data = {};
        $.each(frdata, function () {
            data[this.name] = this.value
        });
        var param = {
            action: "GetTaskOrderData",
            data: JSON.stringify([data]),
            pageSize: page.pageSize,
            pageNumber: page.pageNumber==0?1:page.pageNumber,
        };
        page.post(param, function (res) {
            page.pagetotal = res.RowCount;
            $('#OrderTabel').datagrid('loadData', res.DBTable);
        });
    },
    GetSpec: function () {
        var row = $('#OrderTabel').datagrid('getSelected');
        var param = {
            action: "GetSpec",
            workflowid: row.WORKFLOWID,
            ContainerId: row.CONTAINERID,
            ContainerNo: row.TOGETHERFLAG,
            mfgorderid:row.MFGORDERID
        };
        var index = $('#OrderTabel').datagrid('getRowIndex', row);
        page.post(param, function (res) {
            $('#SpecTable').datagrid('loadData', res.DBTable);
            $('#OrderTabel').datagrid('updateRow', { index: index, row: { FULLTIME: res.Message} });
        });
    },
    //获取大小件信息
    GetBigSmallData: function (workflowstepid) {
        page.selectID = null;
        var row = $('#OrderTabel').datagrid('getSelected');
        var param = {
            action: "GetBigSmallData",
            workflowstepid: workflowstepid,
            ContainerNo: row.TOGETHERFLAG,
            ContainerID: row.CONTAINERID,
            mfgorderid:row.MFGORDERID
        };
        page.post(param, function (res) {
            $('#BigTabel').datagrid('loadData', res.DBTable);
            $('#SmallTabel').datagrid('loadData', res.ReturnData);
        });
    },
    ///设置齐套时间
    SetFullTime: function () {
        var time = $('#SetTime').datetimebox('getValue');
        if (page.selectID != null) {
            $('#' + page.selectID).datagrid('updateRow', { index: page.rowindex, row: { FULLTIME: time} });
            var row = $('#' + page.selectID).datagrid('getSelected');
            var param = {
                action: "SetFullTime",
                PARTMENUINFOID: row.PARTMENUINFOID,
                time: time
            };
            page.post(param, function (res) {
                if (res.Result) { page.GetSpec(); page.GetBigSmallData(''); }
                displayMessage(res.Message, res.Result);
            });
        } else {
            displayMessage('请先一条选择大小件记录，再进行操作', false);
        }
    },
    //清除方法，重要！！！
    reset: function (iscondition, isresult) {
        clearMessage();
    },

    //post数据
    post: function (param, callback) {
        $.ajax({
            type: "Post",
            url: page.ajaxUrl,
            data: param,
            cashe: false,
            async: true,
            dataType: "json",
            beforeSend: function () {
                $.messager.progress({ text: '', msg: '处理中...' });
            },
            success: function (data) {
                $.messager.progress('close');
                callback(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.messager.progress('close');
                displayMessage(XMLHttpRequest.responseText, false);
            }
        });
    }
}
$(function () {
    page.init();
});